package com.tyl.cas;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1999);

        Lock lock=new ReentrantLock();
        //捣乱线程
        System.out.println(atomicInteger.compareAndSet(1999, 2000));
        System.out.println(atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(2000, 555));
        System.out.println(atomicInteger.get());
        //期望线程
        System.out.println(atomicInteger.compareAndSet(555, 7777));
        System.out.println(atomicInteger.get());
    }
}
